package com.wwwarehouse.resource_center.fragment.binding_location_code;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.adapter.carddesk.MyFragmentPagerAdapter;
import com.wwwarehouse.common.custom_widget.CustomViewPagerInternal;
import com.wwwarehouse.common.custom_widget.state_layout.StateLayout;
import com.wwwarehouse.common.tripartite_widget.viewindicator.CirclePageIndicator;
import com.wwwarehouse.resource_center.R;
import com.wwwarehouse.resource_center.bean.binding_location_code.SelectBindWarehouseBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xiaoke.ni on 2017/11/17.
 * 已绑库位码
 */

public class BLCBindedLocationCodeFragment extends BaseFragment implements View.OnClickListener {

    private View mView;

    private StateLayout mStateLayout;
    private CustomViewPagerInternal mCustomViewPagerInternal;
    private CirclePageIndicator mCirclePagerIndicator;
    private MyFragmentPagerAdapter mViewPagerAdapter;

    private int mFragmentListSize;
    private List<Fragment> mFragmentList;

    public static final int PAGE_SIZE = 10;

    /******需要修改的参数*****/
    private List<SelectBindWarehouseBean> list;

    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_select_bind_warehouse, container, false);
        return mView;
    }

    @Override
    public void setTitle() {
        /******需要修改的参数*****/
        if (peekFragment() instanceof BLCBindedLocationCodeFragment) {
            mActivity.setTitle(getString(R.string.resource_blc_binded_location_code));
        }
    }

    @Override
    public void requestDatas() {
        initView();
        initEvent();
        initData();
    }

    private void initData() {
        mStateLayout.showProgressView(true);
    }

    private void initEvent() {
    }

    private void initView() {
        mCustomViewPagerInternal = $(R.id.cvpi);
        mCirclePagerIndicator = $(R.id.cpi);
        mStateLayout = $(R.id.slt);
    }

    @Override
    public void onClick(View v) {

    }

    /******需要修改的参数*****/
    private void fillData(){
        mStateLayout.showContentView();
        if (list == null)
            return;
        int total = list.size();
        int remainder = total % PAGE_SIZE;
        if (remainder == 0) {
            mFragmentListSize = total / PAGE_SIZE;
        } else {
            mFragmentListSize = total / PAGE_SIZE + 1;
        }
        if (mFragmentListSize > 1) {
            for (int i = 0; i < mFragmentListSize; i++) {
                List<SelectBindWarehouseBean> mDataList = new ArrayList<>();
                for (int j = 0; j < PAGE_SIZE; j++) {
                    if (i * PAGE_SIZE + j <list.size())
                        mDataList.add(list.get(i * PAGE_SIZE + j));
                }
                mFragmentList.add(BLCSelectBindWarehouseListFragment.newInstance(i + 1 + "", mDataList));
            }
        } else {
            mFragmentList.add(BLCSelectBindWarehouseListFragment.newInstance(1 + "", list));
        }
        mViewPagerAdapter = new MyFragmentPagerAdapter(getChildFragmentManager(), mFragmentList);
        mCustomViewPagerInternal.setAdapter(mViewPagerAdapter);
        mCirclePagerIndicator.setViewPager(mCustomViewPagerInternal);
    }
}
